package com.two.shopping.service.serviceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.two.shopping.mapper.ILoginMapper;
import com.two.shopping.mapper.IOrderMapper;
import com.two.shopping.pojo.Commodity;
import com.two.shopping.pojo.Orders;
import com.two.shopping.pojo.PageBean;
import com.two.shopping.pojo.User;
import com.two.shopping.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements IOrderService {
    @Autowired
    IOrderMapper orderMapper;
    ILoginMapper loginMapper;

    @Override
    public List<Orders> allSelectOrders(User user) {
        user.setId(1);
        User user1 = loginMapper.selectId(user.getId());
        return orderMapper.allSelectOrdersId(user);
    }

    public void fahuo(Orders orders) {
        orderMapper.fahuo(orders);
    }
    public void shouhuo(Orders orders) {
        orderMapper.shouhuo(orders);
    }

    @Override
    public PageBean allSelectOrders(Integer page, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        List<Orders> list = orderMapper.allSelectOrders();

        Page<Orders> p = (Page<Orders>) list;
        //封装至PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }
}
